<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SJ1</title>
    <style>
        ul li{
            
            list-style: none;

        }
        li{
            display:inline;
            /* padding-top:100px;
            padding: 30px; */

        }
        button{
            padding: 10px 25px;
            border: none;
            
        }
   
        .classA{
            background-color: red;
        }
        
        span{
            background-color: green;
                                                                                                                
        }
     
       
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in sites">
                <button v-on:click='fn(index)' v-bind:class="[item.falg ? 'classA': 'classB']" >{{ item.name }}</button>
            
            </li>
            
        </ul>
        <div>选择了<span>{{bool}}</span></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        var vm=new Vue({
            el:'#app',
            data:{
                bool:'',
                
                sites:[
                    {name:'HTML',falg:false},
                    {name:'CSS',falg:false},
                    {name:'JavaScript',falg:false},
                    {name:'Vue.js',falg:false},
                   
                ]
            },
            methods:{
                fn:function(number){
                   for(var i=0;i<this.sites.length;i++){
                        if(number==i){
                            this.sites[i].falg=!this.sites[i].falg;
                            this.bool=this.sites[i].name;
                        }else{
                            this.sites[i].falg=false;
                        }
                   }
                }
            }
        })
    </script>
    
</body>
</html>